define([
		'vue',
		'config',
		'common',
	],function(Vue,config,utils){
	'use strict';

	var avatarListView=new Vue({
		el:'#app',
		data:{
			sex:'',
			logoImg:'',
			userTypeId:'',
			isUpdated: false,
			isFirst:true
		},
		created:function(){
			utils.userToken();

			var _this=this;
			_this.backtype =utils.getQueryVariable('type');

			// window.addEventListener('popstate',function() {
		       		
	  //      		if(this.backtype == 1){
			// 		window.location.href='personalData.html?type=1';
	  //      		}else{
	  //      			window.location.href='personalData.html';
	  //      		}
		 //    })

			var url = utils.getWebUrl('user/personal');
			utils.ajax(url,null,'POST',function(res){
				_this.sex = res.data.sex;	//0女 1男
				if(_this.sex == 0){
					$('.female').show();
				}else if(_this.sex == 1){
					$('.man').show();
				}else{
					$('.female').show();
					$('.man').show();

				}
				_this.logoImg = res.data.logoImg;
				var liList = $('.avatarList input[name="avatar"]');
				var idArray = new Array();
				var id;
				$.each(liList,function(k,p){
					var id = $(p).parents('li').data('id');
					if(id === _this.logoImg){
						var picPath = $(liList[k]).parents('li').data('id');
						var sex;
						if(picPath.indexOf('boy') === -1){
							sex = 0;
						}else{
							sex = 1;
						}
						utils.ajax(utils.getWebUrl('user/update'),{
							picPath: picPath,
							sex: sex
						},'POST',function(res){
							$(liList[k]).iCheck('check');
						},null,function(){
							$('.DataLoading').hide();
						})
					}
				})


			},function(){
				$('.DataLoading').show();
			})
		},
		updated:function(){
			this.isUpdated = true;
			$('.avatarList input[name="avatar"]').show();
			$(document).ready(function(){
		        $('.subEntrance input').iCheck({
		          checkboxClass: 'icheckbox_square-blue',
		          radioClass: 'iradio_square-blue',
		          increaseArea: '20%'
		        });	
		     });
		},
		directives:{
			select:{
				inserted:function(el, binding){
					var binding =binding;
					$('.avatarList input[name="avatar"]').on('ifChecked',function(event){
						var fnc = binding.value;   
   						fnc(event);
					})
				}
			}
		},
		methods:{
			back: function() {
				if(this.backtype == 1){
					window.location.href='personalData.html?type=1';
	       		}else{
	       			window.location.href='personalData.html';
	       		}
			},
			select:function(event){
				var _this = this;

				if(_this.isFirst){
					_this.isFirst = false;
				  	return;
				}
				
				var $target = $(event.currentTarget);
				var picPath = $target.parents('li').data('id');
				$target.iCheck('check');
				var sex;
				if(picPath.indexOf('boy') === -1){
					sex = 0;
				}else{
					sex = 1;
				}

				var url = utils.getWebUrl('user/update');
				var data= {
					picPath: picPath,
					sex: sex
				};
				utils.ajax(url,data,'POST',function(res){
					if(_this.backtype == 1){
						window.location.href='personalData.html?type=1';
		       		}else{
		       			window.location.href='personalData.html';
		       		}
				},function(){
					$('.DataLoading').show();
				},function(){
					$('.DataLoading').hide();
				})
			}
		}
	})

	return avatarListView
});